package graphics.datastructures.hierarchalbb;

import java.util.Collection;

import graphics.datastructures.BoundingBox;
import graphics.datastructures.SimpleModel;
import graphics.datastructures.Triangle;
import graphics.raytracing.CastResult;
import graphics.raytracing.Ray;
import graphics.raytracing.Tracable;

class LeafBox<T extends Tracable<? extends Tracable<T>>> implements Box<T> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1191841996003052819L;
	private Tracable<T> model;
	private BoundingBox<T> _box;
	public LeafBox(Collection<T> tries,BoundingBox<T> box)
	{
		if(tries==null||box==null)
			throw new IllegalArgumentException("nullpointers..");
		model=new SimpleModel<T>(tries);
		_box =box;
	}
	@Override
	public CastResult<T> cast(Ray ray) {
		return (_box.intersects(ray))?model.cast(ray):null;
	}
	@Override
	public float[][] getBB() {
		return model.getBB();
	}
	@Override
	public BoundingBox getBoundingBox() {
		return _box;
	}
}
